/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.attence;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.attence.DutyRegister;
import com.unis.service.attence.DutyRegisterService;

/**
 * @author Administrator (email:raulcsj@163.com)
 * @since 2013-01-31
 */
@Controller
@RequestMapping("/dutyregister")
public class DutyRegisterController {

    private DutyRegisterService dutyregisterService;

    /****************************************
     * Insert a instace of DutyRegister
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertDutyRegister(@RequestBody DutyRegister dutyregister) throws Exception {
        dutyregister.setStatmentId("DutyRegister.insert");
        String status = "failure";
        dutyregisterService.insert(dutyregister);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of DutyRegister
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody DutyRegister dutyregister) throws Exception {
        dutyregister.setStatmentId("DutyRegister.update");
        String status = "failure";
        dutyregisterService.update(dutyregister);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of DutyRegister
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody DutyRegister dutyregister) throws Exception {
        dutyregister.setStatmentId("DutyRegister.delete");
        String status = "failure";
        dutyregisterService.batchDelete(dutyregister);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of DutyRegister
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        DutyRegister dutyregister = new DutyRegister();
        dutyregister.setStatmentId("DutyRegister.queryAsList");
        BeanUtils.populate(dutyregister, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(dutyregister, pageMap);
        List<BaseModel> dutyregisterList = dutyregisterService.queryAsList(dutyregister);
        Map<String, Object> renderMap = GridUIMapper.render(dutyregister, dutyregisterList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of DutyRegister
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody DutyRegister dutyregister) throws Exception {
        dutyregister.setStatmentId("DutyRegister.queryAsObject");
        return dutyregisterService.queryAsObject(dutyregister);
    }

    @RequestMapping("/page")
    public String forword() {
        return "attence/dutyregisterList";
    }

    @Resource
    public void setDutyRegisterService(DutyRegisterService dutyregisterService) {
        this.dutyregisterService = dutyregisterService;
    }
}
